//
//  YAYINotifyCell.m
//  yayi
//
//  Created by Veer on 16/3/22.
//  Copyright © 2016年 hxp. All rights reserved.
//

#import "YAYINotifyCell.h"
#import "YAYISettingItemModel.h"

@implementation YAYINotifyCell

- (void)setModel:(YAYISettingItemModel *)model
{
    //[super setItem:item];
    _model = model;
    
    self.textLabel.text = model.name;
    
//    if (!model.isHaveArrow) {
//        self.accessoryType = UITableViewCellAccessoryNone;
//    }
    
    if (model.detail) {
        self.accessoryType = UITableViewCellAccessoryNone;
        self.detailTextLabel.text = model.detail;
        
    }else{
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        UISwitch *sw = [[UISwitch alloc] init];
        sw.onTintColor = YAYIColor(101, 173, 243);
        self.sw = sw;
        self.accessoryView = sw;
        
        sw.on = model.isOn;
        
        [sw addTarget:self action:@selector(switchClick:) forControlEvents:UIControlEventValueChanged];
    }
}


+ (instancetype)cellWith:(UITableView *)tableview
{
    static NSString *cellID = @"notifycell";
    
    YAYINotifyCell *cell = [tableview dequeueReusableCellWithIdentifier:cellID];
    
    if (nil == cell) {
        cell = [[YAYINotifyCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
    }
    
    return cell;
}


//
- (void)switchClick:(UISwitch *)sw
{
    YAYILog(@"switch:%d", sw.isOn);
    if (self.switchChangeOperation) {
        self.switchChangeOperation(sw.isOn);
    }
}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        self.textLabel.textColor = YAYIColor(72, 69, 72);
        self.detailTextLabel.textColor = [UIColor grayColor];
        
        self.textLabel.font = [UIFont systemFontOfSize:17];
        self.textLabel.textColor = YAYIColor(93, 90, 93);
        self.detailTextLabel.font = [UIFont systemFontOfSize:17];
        self.detailTextLabel.textColor = YAYIColor(146, 146, 146);
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


@end
